package com.wzp.yyptproject.controller;

import com.wzp.yyptproject.entity.ImgName;
import com.wzp.yyptproject.entity.User;
import com.wzp.yyptproject.repository.UserRepository;
import com.wzp.yyptproject.until.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
public class FTPController {
    @Autowired
    private UserRepository userRepository;
    @RequestMapping(value = "/getImage",method = RequestMethod.POST)
    public Map getImage(@RequestBody User user){
        System.out.println("=======================");
        User user1= userRepository.findAndByUnameAndUidcard(user.getUname(),user.getUidcard());
        System.out.println(user1);
        System.out.println(user1.getUhead());
        String imgname = (String)user1.getUhead();
        System.out.println(imgname);
        if (imgname==null){
            imgname = "morentouxiang.jpg";
            System.out.println(imgname);
        }

        String url = "ftp://192.168.195.1:21/yypt/"+imgname;

        String str="";
        Map map = new HashMap();
        str= Controller.GetImageStrFromUrl(url);	//读取输入流,转换为Base64字符
//        System.out.println(str);
        map.put("image",str);
        return map;
    }
}
